﻿#include <iostream>

using namespace std;

class LeiFeng {
public:
    void Sweep() {
        cout << "扫地" << endl;
    }
    void Wash() {
        cout << "洗衣" << endl;
    }
    void BuyRice() {
        cout << "买米" << endl;
    }
};

class Undergraduate : public LeiFeng {};

class Volunteer : public LeiFeng {};

class IFactory {
public:
    virtual LeiFeng* CreateLeiFeng() = 0;
    virtual ~IFactory() {}
};

class UndergraduateFactory : public IFactory {
public:
    virtual LeiFeng* CreateLeiFeng() override {
        return new Undergraduate();
    }
};

class VolunteerFactory : public IFactory {
public:
    virtual LeiFeng* CreateLeiFeng() override {
        return new Volunteer();
    }
};

int main(int argc, char *argv[])
{
    IFactory* factory = new UndergraduateFactory();
    LeiFeng* student = factory->CreateLeiFeng();

    student->BuyRice();
    student->Sweep();
    student->Wash();

    return 0;
}
